#!/usr/bin/env bash

# Generates all the pre-translated code in lib/translated/{locale}.

set -e
rm -rf lib
rm -rf es

node scripts/build-translations.js --empty

CPUS=$(node --eval "console.log(Math.max(1, require('os').cpus().length))")
echo "building pretranslated output in lib/translated $CPUS at a time ..."

ls locales/*.json | \
  xargs basename -s .json | \
  xargs -t -n 1 -P $CPUS -I % env \
    BUILD_LOCALE=% npx babel --out-dir es/% --ignore __*/* --copy-files src

ls locales/*.json | \
  xargs basename -s .json | \
  xargs -t -n 1 -P $CPUS -I % env \
    TRANSPILE=true BUILD_LOCALE=%  npx babel --out-dir lib/% --ignore __*/* --copy-files src

node scripts/build-translations.js

npx babel --out-dir es/ --ignore __*/* --copy-files src
TRANSPILE=true  npx babel --out-dir lib/ --ignore __*/* --copy-files src
